﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>我的任务</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
	<script charset="utf-8" src="../js/find.js"></script>
	<link rel="stylesheet" href="../css/default.css" />
<script type="text/javascript" src="../js/manhuaDate.1.0.js"></script> 
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
$(function(){
	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	$("input[type='file']").change(function(){
		$(this).prev().prev().val($(this).val())
	})
	$("#status").change(function(){
		if($("#status").val()==2){
			$("#showNextTime").show()
		}else{
			$("#showNextTime").hide()
		}
	})
	
	 $("#dtBegin").val(getToday());
	$("#dtEnd").val(getToday()); 
});

var shopPageCount=0;
var shopCount=0;
var pageCount=0;
var pageIndex=1;
var resultIndex=1;
var resultId = null;
$(function(){
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
			$("#research").attr("disabled",false);
			
		}else{
			$("#shopName").attr("disabled",true);

		}
	});
	

	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	
});
function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name);
}

function getParamToshopS(id,name){
	var shopflag=$("#shopflag").val();
	if(shopflag==1){
		$("#shopName2").val(name);
		$("#shopId").val(id);
		$("#keyId").html("")
		chooseKeyId();
	}else{
		
	var htm="<option value='"+id+"'>"+name+"</option>";
	$("#shopName").html(htm);
	$("#shopName").val(id);
	
	chooseKeyId2();
	}
	closeShopShow();
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("");
}
function InitShopList(shopPageIndex){
	var shopName=$("#searchName").val().replace(/\s/gi,'');
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + shopPageIndex + "/5",
		success : function(data) {
			var rst = JSON.parse(data);
			 if(IsEmpty(rst)){
					art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
					return false;
					}
					if(rst.state==0){
						$("#shopList tbody tr").remove();

						initShopTable(rst);
						$("table[id='shopList'] tbody tr").each(function(){
							$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

						})	
						if(rst.result.len > 0){
							 var shu = rst.result.len;
							 shopCount = Math.ceil(shu/5);					
							 }else{
									shopCount==0;
							 }
						 $("#shopPager").pager({ pagenumber: ++shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
						 addMargin($("#shopShow"));	
						 }else if(rst.state==1){
						art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
					}else{
						checkStateShowErrorMsgAndDealResult(data);
					}
		}	
	});
	
		
	
}
ShopPageClick = function(pageclickednumber) {
    $("#shopPager").pager({ pagenumber: --pageclickednumber, pagecount: shopCount, buttonClickCallback: ShopPageClick });
    $("#result").html("Clicked Page " + pageclickednumber);
    InitShopList(pageclickednumber);
};
function search2(){
	InitShopList(0);
}

function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		Loadtable(json,params,"shopList");
	}
}
function Loadtable(json, params, tableId){
	var phArray = new Array();
	var count = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d == "null" ? " " : d) + "</td>");
					}
				});
			});
		});
		
	}
	

	
}

function showShopList(shopflag){
	$("#shopflag").val(shopflag);
	$("#shopName").blur();
	$("#shopShow,#yinying").show();
	InitShopList(0);
}

function getFucnMenuDetailList(page){
	if(IsEmpty(page)){
		pageIndex=1
	}else{
		pageIndex = page
	}
	var status = $("#searchStatus").val();
	var dtBegin = $("#dtBegin").val();
	var dtEnd  = $("#dtEnd").val();
	var remindId = $("#remindID").val();
	
	param={'status':status,'dtAssignTimeBegin':dtBegin,'dtAssignTimeEnd':dtEnd,'remindId':remindId}
	
	 adList = _findInfo("../taskRemind/find/myTaskRemindList/"+(pageIndex -1)+"/10", param);
	if(adList.state==0){
		$("#funcMenuList tbody").empty();
		 for ( var i = 0; i < adList.result.data.length; i++) {
				var htm = "<tr>";
			 htm+= "<td>"+ _getStringOfJson(i, adList, "AssignTime").substring(0,10)+"</td>";
				htm+="<td>"+ _getStringOfJson(i, adList, "RemindName")+"</td>";
				htm+="<td>"+ _getStringOfJson(i, adList, "CustName")+"</td>";
				htm+="<td>"+ _getStringOfJson(i, adList, "Mp")+"</td>";
				htm+="<td>"+ _getStringOfJson(i, adList, "License")+"</td>";
			htm+="<td>"+ _getStringOfJson(i, adList, "TaskMemo")+"</td>";
			htm+="<td>"+ _getStringOfJson(i, adList, "AssignName")+"</td>";
			htm+="<td>"+ _getStringOfJson(i, adList, "staName")+"</td>";
			var status = _getIntOfJson(i, adList, "status");
			if(status==1){
				htm+="<td><input class=\"common_btn to_update\" type=\"button\" value=\"处理\" onclick='updateAd("+_getStringOfJson(i, adList, "ID")+")' ></td>"
			}else if(status == 2){
			htm+="<td><input class=\"common_btn to_update\" type=\"button\" value=\"处理\" onclick='updateAd("+_getStringOfJson(i, adList, "ID")+")' ><br><input class=\"del\" type=\"button\" value=\"历史\" onclick='getDetil("+_getStringOfJson(i, adList, "ID")+")' ></td>"
			}else if(status >2){
				htm+="<td><input class=\"del\" type=\"button\" value=\"历史\" onclick='getDetil("+_getStringOfJson(i, adList, "ID")+")' ></td>"
			}
			htm+= "</tr>"
			$("#funcMenuList tbody").append(htm)
		}
		 _loadPage("pager", pageIndex, 10, adList, getFucnMenuDetailList, "NoResult")
		$("#sup").html("共"+adList.result.len+"条");	
		
		 
	}
	
}



function updateAd(id){
	$("#updateId").val(id);
	$("#status").val(2)
	$("#showNextTime").show()
	$("#yinying1,#mainMenu").show();
}

function save(){
	var id  = $("#updateId").val()
	var reply= $("#reply").val()
	var result= $("#result").val()
	var status= $("#status").val()
	var nextTime= $("#nextTime").val()
	if(IsEmpty(result)){
		alert("请输入处理结果");
		return false;
	}
	
	var json = null;
	if(status==2){
		if(IsEmpty(nextTime)){
			alert("请输入下次跟踪时间");
			return false;
		}
		var heads = new Array('AssignTime','Status','id');
		var datas = new Array(nextTime,status,id);
		 json = _getJsonParseEditStr(heads, datas);
	}else{
		var heads = new Array('Status','id');
		var datas = new Array(status,id);
		 json = _getJsonParseEditStr(heads, datas);
	}
	
	var resultHead = new Array('reply','result','taskRemindId');
	var resultdata = new Array(reply,result,id);
	var resultJson = _getJsonParseInsertStr(resultHead, resultdata);
	
	var dt = _insertInfo("../taskRemindResult/insert", {'data':resultJson,'taskRemind':json})
	if(IsNotEmpty(dt)&&dt.state==0){
		getFucnMenuDetailList(pageIndex);
		$("#result").val("");
		$("#reply").val("");
		$("#yinying1,#mainMenu").hide();
	
	}
	
}

function getDetil(id){
	resultId = id;
	resultIndex = 1;
	getResult(1)
	var result = _findInfo("../taskRemindResult/find/taskRemindResult", {'taskRemindId':id})
}

function getResult(page){
	if(IsEmpty(page)){
		resultIndex = 1
	}else{
		resultIndex = page
	}
	var result = _findInfo("../taskRemindResult/find/taskRemindResult/"+(resultIndex - 1)+"/5", {'taskRemindId':resultId})
	if(IsNotEmpty(result)&&result.state==0){
		$("#resultList tbody").empty()
		for ( var i = 0; i < result.result.data.length; i++) {
			var htm="<tr>"
				htm+="<td>"+_getStringOfJson(i, result, "createdTime")+"</td>"
				htm+="<td>"+_getStringOfJson(i, result, "reply")+"</td>"
				htm+="<td>"+_getStringOfJson(i, result, "result")+"</td>"
				htm+="</tr>";
		$("#resultList tbody").append(htm)
		}
		_loadPage("resultPage", resultIndex, 5, result, getResult, null)
		addMargin($("#resultShow"))
		$("#resultShow,#yinying1").show()
	}

}


	


</script>


</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<div id="yinying"></div>
<div id="yinying1"></div>
<div id="window_changeff" class="hideDiv setHTML" >
	<textarea id="editIndex" name="editIndex"></textarea>
	<div class="BottomBtn">
        <input type="button" value="确定" class="common_btn" onclick="saveHtml()" >
        <input type="button" value="取消" style="background-color: red;" class="common_btn" onclick="cancelHtml()" >
      </div>
</div>
<div id="resultShow" class="hideDiv">
    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="$('#resultShow,#yinying1').hide()" >X</span> </div>
    <table   id="resultList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
    <tr>
    <th>跟踪时间</th>
    <th>回复客户</th>
    <th>跟踪结果</th>
    </tr>
    </thead>
    <tbody></tbody>
    </table>
    	<div id="resultPage" class="shopPager"></div>
    </div>

<div id="shopShow" class="hideDiv">
    <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
    <div class="bottom_search"><div class="serWrapper"><input type="text" id="searchName" class="txt"><strong class="refresh" onclick="$('#searchName').val('')">清空</strong></div><input class="common_btn" type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()"></div>
    <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
    <tr>
    <th>店面ID</th>
    <th>店面名称</th>
    <th>电话</th>
    <th>操作</th>
    </tr>
    </thead>
    </table>
    	<div id="shopPager"></div>
    	<input type="hidden" id="shopflag" >
    </div>
<script type="text/javascript">
$(function(){
	refreshInput($(".serWrapper"));
		$(this).prev().prev().val($(this).val())
		
	})
	

</script>

<div class="member_search publish WX hideDiv" id='mainMenu'>
<div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
       <form name="fm1" action="#" target="post">
       	<input type="hidden" id="updateId">
    <p><span>回复客户：</span>
        &nbsp;<textarea id="reply" class="reset"></textarea>
    </p>
     <p><span>跟踪结果：</span>
        &nbsp;<textarea id="result" class="reset"></textarea>
      </p>
  <p><span>状态：</span>
        <select id="status"  >
        <option value="2">继续跟踪</option>
        <option value='3'>已完成</option>
        <option value="4">取消</option>
        </select></p>
        <p  id="showNextTime">
        <span>下次跟踪时间：</span>
             <input type="text" id="nextTime" class="doubledate">
             </p>     
      <div class="BottomBtn">
        <input type="button"  value="确认" onclick="save()" id="save_btn">
      </div>
        </form>      
       </div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">我的任务</div>
    <div class="member_search">
      <p>
        <span>任务类型：</span>
			<select id="remindID">
			<option value="">全部</option>
			
			<option value="1">生日提醒</option>
			<option value="2">会员到期</option>
			<option value="4">钢瓶检验提醒</option>
			<option value="5">保险到期提醒</option>
			<option value="6">保养到期提醒</option>
			<option value="7">试乘试驾预约</option>
			<option value="8">服务预约</option>
			<option value="9">保险预约</option>
			<option value="10">二手车评估</option>
			
			</select>
       <span>起始日期：</span>
		<input id="dtBegin" class="doubledate" type="text" value="" >
		 <span>截止日期：</span>
		<input id="dtEnd" class="doubledate" type="text" value="">
		<p>
		     <span>任务状态：</span>
			<select id="searchStatus">
			<option value="">全部</option>
			<option value="2">跟踪中</option>
			<option value="1">未跟踪</option>
			<option value="3">完成</option>
			<option value="4">取消</option>
			</select>
        		<input class="btn" id="research" name="查询" type="button" value="查询" onClick="getFucnMenuDetailList(1)" ></p>
        </div>
       <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="funcMenuList">
    	<caption><strong>任务列表       <span id="sup">共0条</span>  </strong>
<!--     	<input type="button" class="common_btn" value="增加" onclick="toAdd()">
 -->    	</caption>
    	<thead>
    	<tr>
    		<th >任务日期</th>
        	<th >任务类型</th>
        	<th >客户姓名</th>
        	<th >客户电话</th>
        	<th >车牌号</th>
        	<th >任务描述</th>
        	<th >操作员</th>
        	<th >状态</th>
        	<th >操作</th>
        </tr>
        </thead>
       	<tbody>
       		
       	</tbody>
    </table>
      <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(5,3);
</script>
</body>
<!-- InstanceEnd -->
</html>
